﻿@{
    Layout = null;
}
<div id="divtoolbar" class="toolbarapp">
    <div class="content" style="float:left">
        <span id="toolbaraction" style='border-width:0px; height:20px'></span>
        <script>

            function onSelectMenu(e)
            {
                var item = $(e.item),
               menuElement = item.closest(".k-menu"),
               dataItem = this.options.dataSource,
               index = item.parentsUntil(menuElement, ".k-item").map(function () {
                   return $(this).index();
               }).get().reverse();

                index.push(item.index());

                for (var i = -1, len = index.length; ++i < len;) {
                    dataItem = dataItem[index[i]];
                    dataItem = i < len-1 ? dataItem.items : dataItem;
                }

                if(dataItem.urlfunction =="clear")
                {
                    PostServer('@Url.Action("ClearCaches","Shared")')
                    document.location.href = '@Url.Action("Logout", "Home")';
                }
                else if(dataItem.urlfunction =="Module")
                {

                    if (!windowModule.data("kendoWindow")) {
                        windowModule.kendoWindow({
                            width: "300px",
                            title: "Select Module",
                            resizable: false,
                            refresh: function () { this.center(); }
                        });
                    }

                    windowModule.data("kendoWindow").center().open();
                }
                else
                {
                    var per = PostServer('@Url.Action("GetExecPer", "Shared")?type=2&functionID=' + dataItem.urlfunctionID);
                    if(per.Active)
                        ShowWindowCallback(dataItem.urlfunction,0,0,'Create ' + dataItem.text);
                    else
                        ShowMessage('AccNet i', 'YouNotPermission', 'You not permission for this function.', null, null, 'OK');
                }
            }

            $("#toolbaraction").kendoMenu({
                select: onSelectMenu,
                dataSource: [

                    {
                        text: "@Html.LOBHtmlHelper().T( "NewTransaction")",encoded: false,
                        items: [
                            @{
                                        int i =0;
                                        foreach (LineOfBusiness.Poco.SYS_FunctionList func in ViewBag.FunctionTransactionList)
                                        {

                                            if(i!=0)
                                            {
                                                    @:,
                                            }
                                            @:  { text: "@func.CustomName", imageUrl: "@Html.BaseUrl()Content/default/@func.SmallIcon", urlfunction : "@func.Url/Add",urlfunctionID :"@func.FunctionID" ,encoded: false}

                                            i += 1;
                                        }
                                    }
                        ]
                    },
                    {

                        text: "@Html.LOBHtmlHelper().T("New Record")",
                        items: [
                            @{
                                        int j =0;
                                        foreach (LineOfBusiness.Poco.SYS_FunctionList mod in ViewBag.FunctionList)
                                        {
                                            if(j!=0)
                                            {
                                                @:,
                                            }

                                            @:  { text: "@mod.CustomName", imageUrl: "@Html.BaseUrl()Content/default/@mod.SmallIcon",  encoded: false,
                                                    @: items: [

                                              i = 0;
                                              foreach (LineOfBusiness.Poco.SYS_FunctionList func in ViewBag.FunctionSetupList)
                                              {
                                                  if (func.Module == mod.FunctionID)
                                                  {
                                                      if (i != 0)
                                                      {
                                                        @:,
                                                            }
                                                    @:  { text: "@func.CustomName", imageUrl: "@Html.BaseUrl()Content/default/@func.SmallIcon", urlfunction : "@func.Url/Add",urlfunctionID :"@func.FunctionID",encoded: false }
                                                        i += 1;
                                                  }

                                              }

                                            @: ]}
                                            j += 1;

                                        }
                                    }
                        ]
                    },
                     {
                         text: "@Html.LOBHtmlHelper().T("System")",encoded: false,
                         items: [
                              { text: "@Html.LOBHtmlHelper().T("ClearCaches")", urlfunction : "clear",encoded: false },

                              { text: "@Html.LOBHtmlHelper().T("ViewModule")", urlfunction : "Module",encoded: false }

                         ]
                     }
                    @*,
                            {
                                text: "Report",
                                items: [
                                    @{
                                        j =0;
                                        foreach (LV.Poco.SYS_FunctionList mod in ViewBag.FunctionList)
                                        {
                                            if(j!=0)
                                            {
                                                @:,
                                            }

                                            @:  { text: "@mod.CustomName", imageUrl: "@Html.BaseUrl()Content/default/@mod.SmallIcon",
                                                    @: items: [

                                            i = 0;
                                            foreach (LV.Poco.SYS_FunctionList func in ViewBag.FunctionReportList)
                                            {
                                                if(func.Module  == mod.FunctionID)
                                                {
                                                    if (i != 0)
                                                    {
                                                        @:,
                                                        }
                                                    @:  { text: "@func.CustomName", imageUrl: "@Html.BaseUrl()Content/default/@func.SmallIcon", urlfunction : "@func.Url"  }
                                                    i += 1;
                                                }

                                            }

                                            @: ]}
                                            j += 1;

                                        }
                                    }
                                ]
                            }*@
                ]
            });
        </script>


    </div>
    <div style="float:left;margin-top:3px;">
        @(Html.Kendo().AutoComplete()
                              .Name("autofunction")
                              .DataTextField("text")
                              .Filter("contains")
                              .MinLength(3)
                              .HtmlAttributes(new { style = "width:150px;height:14px;" })
                              .DataSource(source =>
                              {
                                  source.Read(read =>
                                  {
                                      read.Action("GetFunctionAuto", "Shared");
                                  })
                                  .ServerFiltering(true);

                              })
                              .Events(o => o.Select("onselectauto"))
        )
    </div>
    <div style="float:right; margin-right:10px;margin-top:4px;height:20px;width:50px">
        <img src="@Url.Content("~/Content/default/images/Icons/help.png")" style="margin-top:4px" />
        <span style="color:blue;float:right;margin-left:5px;margin-top:6px"> Help</span>
    </div>
</div>

<div id="divMid" class="mid">
    <div class="barleft">
        <div class="headerModule">
            <div class="headertitle">
            </div>

            <div style="float: right; width: 30px; height: 20px">
                <img src="@Url.Content("~/Content/default/images/rightleft.png")" onclick="HideLeftPanel()" style="margin-top:6px;margin-right:10px;cursor:pointer" />
            </div>
        </div>
        <div class="function">
            @foreach (LineOfBusiness.Poco.SYS_FunctionList func in ViewBag.FunctionList)
            {
                <div id="module_@func.FunctionID" class="divmodule">
                    @(Html.Kendo().TreeView()
            .Name("treeview" + func.FunctionID)
            .HtmlAttributes(new { @class = "demo-section" })
            .DataTextField("Name")
            .DataSource(dataSource => dataSource
                .Read(read => read
                    .Action("FunctionModule", "Shared", new { module = func.Module })
                )
            )
            .Events(o => o.Select("SelectFunction"))
                    )
                </div>
            }

        </div>

        <div class="module">
            @foreach (LineOfBusiness.Poco.SYS_FunctionList func in ViewBag.FunctionList)
            {
                <div class="moduleitem" id="@func.Module">

                    <img width="20px" height="20px" src="@Url.Content("~/Content/default/")@func.SmallIcon.Replace(@"\\", @"/")" style="border:0px" alt="@func.CustomName" />
                    <span class="moduletext">@func.CustomName</span>
                </div>
            }
        </div>


        <div id="windowmodule">
            @foreach (LineOfBusiness.Poco.SYS_FunctionList func in ViewBag.FunctionList)
            {
                <div>
                    <input id="vmod_@func.Module" name="vmod_@func.Module" class="chkshowmodule" type="checkbox" checked="checked" />
                    <img width="20px" height="20px" src="@Url.Content("~/Content/default/")@func.SmallIcon.Replace(@"\\", @"/")" style="border:0px" alt="@func.CustomName" />
                    <span class="moduletext">@func.CustomName</span>
                </div>
            }
        </div>
        <script type="text/javascript">
            var moduleNumber = @ViewBag.FunctionList.Count;
            $(document).ready(function ()
            {
                @foreach (LineOfBusiness.Poco.SYS_FunctionList func in ViewBag.FunctionList)
        {

            @: if($.cookie("vmod_@func.Module")=="false")
                                @:{
                                    @: $("#@func.Module").hide();
                                    @: moduleNumber = moduleNumber-1;
                                    @: $('input:checkbox[name=vmod_@func.Module]').attr('checked', false);
                                @:}
                        }
                $('.chkshowmodule').change(ShowHideModule);
            });
            function ShowHideModule(){
                var name = this.id;
                var check = $(this).is(':checked');

                var m = name.replace('vmod_','');
                if(check)
                {
                    $("#" +m).show();
                    moduleNumber = moduleNumber+1;
                }
                else
                {
                    $("#" +m).hide();
                    moduleNumber = moduleNumber-1;
                }
                $.cookie("vmod_" + m,check, { expires: 356 })
                resize();
            }
        </script>

        <style scoped>
            .demo-section {
                display: inline-block;
                vertical-align: top;
                text-align: left;
                width: 100%;
            }
        </style>
